package requests

import (
	"github.com/goravel/framework/contracts/http"
	"github.com/goravel/framework/contracts/validation"
	"goravel/app/models/common"
)

type ProductRequest struct {
	Code        string       `form:"code" json:"code"`
	Name        string       `form:"name" json:"name"`
	Unit        string       `form:"unit" json:"unit"`
	Spec        string       `form:"spec" json:"spec"`
	ProductArea string       `form:"product_area"`
	Price       float64      `form:"price" json:"price"`
	SalePrice   float64      `form:"sale_price" json:"sale_price"`
	Stock       int          `form:"stock" json:"stock"`
	Preview     string       `form:"preview" json:"preview"`
	Description string       `form:"description" json:"description"`
	Image       string       `form:"image" json:"image"`
	Banner      string       `form:"banner" json:"banner"`
	Album       common.Album `form:"album" json:"album"`
}

func (r *ProductRequest) Authorize(ctx http.Context) error {
	return nil
}

func (r *ProductRequest) Rules(ctx http.Context) map[string]string {
	return map[string]string{
		"code":       "required",
		"name":       "required",
		"unit":       "required",
		"spec":       "required",
		"price":      "required",
		"sale_price": "required",
		"stock":      "required",
	}
}

func (r *ProductRequest) Messages(ctx http.Context) map[string]string {
	return map[string]string{
		"code.required":       "商品编码不能为空",
		"name.required":       "商品名称不能为空",
		"unit.required":       "商品单位不能为空",
		"spec.required":       "商品规格不能为空",
		"price.required":      "商品价格不能为空",
		"sale_price.required": "商品售价不能为空",
		"stock.required":      "商品库存不能为空",
	}
}

func (r *ProductRequest) Attributes(ctx http.Context) map[string]string {
	return map[string]string{}
}

func (r *ProductRequest) PrepareForValidation(ctx http.Context, data validation.Data) error {
	return nil
}
